package edu.ccut.saturn.studio.wfg.dialog.userdialog;

import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class TreeViewerContentProvider implements ITreeContentProvider {

	@SuppressWarnings("unchecked")
	public Object[] getChildren(Object parentElement) {
		ITreeEntry entry = (ITreeEntry) parentElement;
		List list = entry.getChildren();
		
		if (list == null)
			return new Object[0];
		return list.toArray();
	}

	@SuppressWarnings("unchecked")
	public boolean hasChildren(Object element) {
		ITreeEntry entry = (ITreeEntry) element;
		List list = entry.getChildren();
		return !(list == null || list.isEmpty());
	}

	@SuppressWarnings("unchecked")
	public Object[] getElements(Object inputElement) {
		if (inputElement instanceof List) {
			List input = (List) inputElement;
			return input.toArray();
		}
		return new Object[0];
	}
	
	
	public Object getParent(Object element) {
		return null;
	}


	public void dispose() {
	}

	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	}
}
